﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Ticket_booking : System.Web.UI.Page
{
    Connect cn = new Connect();
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet dt = new DataSet();
        DataView dtv = new DataView();
        DateTime day = new DateTime();
        day = DateTime.Now.Date;
        dt = cn.LoadData("tblMovie", "SELECT * FROM tblMovie WHERE ReleasedDay<='" + day + "' AND CloseDay >='" + day + "'");
        dtv = dt.Tables[0].DefaultView;
        ddlMovie.DataSource = dtv;
        ddlMovie.DataBind();
    }
    protected void lbtnMovie_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton lbtn = (LinkButton)sender;
            string str_Id = lbtn.CommandArgument.ToString();
            Session["Mid"] = str_Id;
            DataSet dt = new DataSet();
            DataView dtv = new DataView();
            dt = cn.LoadData("tblMovieList", "SELECT * FROM tblMovieList WHERE  MovieID='" + str_Id + "' AND StatusC=1");
            dtv = dt.Tables[0].DefaultView;
            ddlDate.DataSource = dtv;
            ddlDate.DataBind();
            lblMovieS.Text = cn.GetNameM(1, "SELECT * FROM tblMovie WHERE  MovieID='" + str_Id + "'");
        }
        catch (Exception)
        {
        }
    }
    protected void lbtnTime_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton lbtn = (LinkButton)sender;
            string str_Time = lbtn.CommandArgument.ToString();
            Session["Time"] = str_Time;
            DataSet dt = new DataSet();
            DataView dtv = new DataView();
            dt = cn.LoadData("tblMovieList", "SELECT * FROM tblMovieList WHERE  MovieID='" + Session["Mid"].ToString() + "' AND DateMovie='" + DateTime.Parse(Session["Date"].ToString()).Date + "' AND TimeMovie='" + DateTime.Parse(str_Time).TimeOfDay + "'AND StatusC=0");
            dtv = dt.Tables[0].DefaultView;
            ddlCinema.DataSource = dtv;
            ddlCinema.DataBind();
            lblTimeS.Text = str_Time;
        }
        catch (Exception)
        {
        }
    }
    protected void ddlDate_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton lbtn = (LinkButton)sender;
            string str_Date = lbtn.CommandArgument.ToString();
            Session["Date"] = str_Date;
            DataSet dt = new DataSet();
            DataView dtv = new DataView();
            dt = cn.LoadData("tblMovieList", "SELECT * FROM tblMovieList WHERE  MovieID='" + Session["Mid"].ToString() + "' AND DateMovie='" + DateTime.Parse(str_Date).Date + "' AND StatusC=0");
            dtv = dt.Tables[0].DefaultView;
            ddlTime.DataSource = dtv;
            ddlTime.DataBind();
            lblDateS.Text = str_Date;
        }
        catch (Exception)
        {
        }
    }
    protected void lbtnCinema_Click(object sender, EventArgs e)
    {
        LinkButton lbtn = (LinkButton)sender;
        string str_Ch = lbtn.CommandArgument.ToString();
        Session["chair"]= str_Ch;
        lblChairS.Text = str_Ch;
    }

    protected void btnSummit_Click(object sender, EventArgs e)
    {
        //string str_ticketId = cn.GetNameM(0, "SELECT * FROM tblTicket WHERE  MovieID='" + Session["Mid"].ToString() + "' AND ChairID ='" + Session["chair"].ToString() + "' AND DateMovie='" + DateTime.Parse(Session["Date"].ToString()).Date + "' AND TimeMovie='" + DateTime.Parse(Session["Time"].ToString()).TimeOfDay + "'AND StatusC=0");
        string str_oid = cn.GetID("tblOrder");
        lblDateS.Text = str_oid;
        //cn.ADD_Edit("IMSERT INTO tblOrder VALUES(OderID='" +str_oid + "',TicketId='"+str_ticketId+"' )");
    }
}